function heredoc(fn) {
    return fn.toString().split('\n').slice(1, -1).join('\n') + '\n'
}
var printerTemp = heredoc(function(){/*
    <div id="receipt" style="width:270px">
    <div class="Drugbox">
        <p style="font-size: 18px;margin:0 auto;text-align:center;">国药控股湖南维安大药房连锁</p>
        <p style="font-size: 18px;margin:0 auto;text-align:center;">有限公司河西店</p>
        <p style="line-height: 3px;">----------------------------------------------------------------------------------------------------</p>
    </div>
    <div >
      <p style="font-size: 12px;margin:0 auto;">交易时间 : {TradingHours}</p>
      <p style="font-size: 12px;margin:0 auto;">流水号 : {SerialNumber}</p>
      <p style="font-size: 12px;margin:0 auto;">会员 : {Member}</p>
    </div>
                            <p style="line-height: 3px;">---------------------------------------------------</p>
    <div >
      <span style="font-size: 12px;display:inline-block;width:25%;float: left;">商品</span>
      <span style="font-size: 12px;display:inline-block;width:25%;float: left;">单价</span>
      <span style="font-size: 12px;display:inline-block;width:25%;float: left;">数量</span>
      <span style="font-size: 12px;display:inline-block;width:25%;float: left;">金额</span>
      <p style="font-size: 12px;margin:0 auto;">{Name}</p>
      <p style="font-size: 12px;margin:0 auto;">{ProductName}</p>
      <p style="font-size: 12px;margin:0 auto;">{Manufacturer}</p>
            <span style="font-size: 12px;display:inline-block;width:25%;float: right;">{AmountMoney}</span>
      <span style="font-size: 12px;display:inline-block;width:25%;float: right;">{Number}</span>
            <span style="font-size: 12px;display:inline-block;width:25%;float: right;">{UnitPrice}</span>

    </div>
      <p style="line-height: 1px;"></p>
        <div >
      <p style="font-size: 12px;margin:0 auto;">有效期 : {Exp}</p>
      <p style="font-size: 12px;margin:0 auto;">批号 : {BatchNumber}</p>
    </div>
                <p style="line-height: 3px;">---------------------------------------------------</p>
    <div  >
      <span style="font-size: 12px;display:inline-block;width:100%;float: left;">合计数量 : {Total}</span>
      <span style="font-size: 12px;display:inline-block;width:100%;float: left;">合计金额 : {TotalMoney}</span>

    </div>
                <p style="line-height: 3px;">---------------------------------------------------</p>
    <div  >
      <p style="font-size: 12px;margin:0 auto;">地址 : {Address}</p>
      <p style="font-size: 12px;margin:0 auto;">电话 : 0731-84912233</p>
      <p style="font-size: 12px;margin:0 auto;">药品属特殊商品,非质量问题概不退<br/>钱款当面点清,请保存本单据.谢谢</p>
      <span style="font-size: 12px;display:inline-block;width:50%;float: left;text-align:center;">关爱生命</span>
      <span style="font-size: 12px;display:inline-block;width:50%;float: left;text-align:center;">呵护健康</span>
    </div>
                <p style="line-height: 3px;">---------------------------------------------------</p>
    <img style="width: 150px;height: 150px;" src="{imgSrc}"/>
          <p style="line-height: 25px;">-</p>


  </div>
 */})



var tagsTemp = heredoc(function(){/*
     <div class="print_container" align="center"  style="padding:4px;">
             <p style="font-size:12px;line-height:14px;padding:0;">设备信息</p>
     <div align="center" style="font-size:12px">
        <img src="{imgUrl}"  alt="" width="60%" srcset="" />
        <p>{code}</p>
     </div>
 </div>
 */})
var miniTagsTemp = heredoc(function(){/*
  <div style="display:flex;padding:0px;margin:3px 0 0 0;align-items:center;">
     <div align="center"  style="font-size:10px;margin-left:5px;">
        <img src="{img0}"  alt="" width="57px" srcset="" />
        <p style="line-height: 10px;margin: 5px 0 0 0;">{code0}</p>
     </div>
          <div align="center" style="font-size:10px;margin-left:35px;">
        <img src="{img1}"  alt="" width="57px" srcset="" />
        <p style="line-height: 10px;margin: 5px 0 0 0;">{code1}</p>
     </div>
      </div>
 */})

var receiptTemp = heredoc(function (){/*
    <div
      style="margin: 40px auto 30px auto;width: 340px;text-align: center;font-size: 24px;line-height: 1.5;">
      常温药品签收单</div>
  <p style="position:absolute;top:0px;left:2px;font-size: 14px;">国药控股湖南有限公司</p>
  <p style="position:absolute;top:13px;left:2px;font-size: 14px;">Sinopharm Group Hunan co.,Ltd</p>
         <p style="float:right;display: block;margin: 0px 20px 20px 0;line-height: 2;">订单组号:{OrderId}</p>

    <div id="receipt" >
      <div class="Drugbox" style="border: 2px solid #333;">
        <div style="border-bottom: 1px solid #333;padding: 5px 20px;">
          <p style="font-weight: bold;font-size: 16px;margin: 8px 0;">配送信息</p>
     <div style="display: flex;align-items: top;font-size: 14px;">
       <span style="width: 54%;display: inline-block;margin: 0px 0 0px 0;line-height: 2;">产名、规格:
         {ProductName}{Specifications}</span>
       <span
         style="width: 21%;display: inline-block;margin: 0px 0 0px 2%;line-height: 2;">批号:{BatchNumber}</span>
       <span
         style="width: 21%;display: inline-block;margin: 0px 0 0px 2%;line-height: 2;">{Exp}</span>
     </div>

          <div style="display: flex;align-items: top;font-size: 14px;">
            <span style="width: 48%;display: inline-block;margin: 0px 0 0px 0;line-height: 2;">单价: {UnitPrice}</span>
            <span style="width: 16%;display: inline-block;margin: 0px 0 0px 4%;line-height: 2;">数量: {Number}</span>
            <span style="width: 26%;display: inline-block;margin: 0px 0 0px 4%;line-height: 2;">金额:
              {AmountMoney}</span>
          </div>

          <div style="display: flex;align-items: top;font-size: 14px;">
            <span style="width: 48%;display: inline-block;margin: 0px 0 0px 0;line-height: 2;">约定送货时间:
              {DeliveryTime}</span>
            <span style="width: 46%;display: inline-block;margin: 0px 0 0px 4%;line-height: 2;">约定送货地点:
              {Address}</span>
          </div>

          <div style="display: flex;align-items: top;font-size: 14px;">
            <span style="width: 48%;display: inline-block;margin: 0px 0 0px 0;line-height: 2;">收货人姓名:
              {ReceivingName}{Insurance}</span>
            <span style="width: 46%;display: inline-block;margin: 0px 0 0px 4%;line-height: 2;">收货人联系方式:
              {Contact}</span>
          </div>

          <div style="display: flex;align-items: top;font-size: 14px;">
            <span style="width: 42%;display: inline-block;margin: 0px 0 0px 0;line-height: 2;">诊断:
          </span>
          </div>
        </div>
        <div style="border-bottom: 1px solid #333;padding: 5px 20px;">
          <p style="font-weight: bold;font-size: 16px;margin: 8px 0;">配送开始记录(由配送人员填写)</p>
          <div style="display: flex;align-items: top;font-size: 14px;">
          <span style="width: 100%;display: inline-block;margin: 0px 0 30px 0;line-height: 2;white-space: pre-wrap">开始配送时间: <span style="margin-right:50px;">年</span> <span style="margin-right:30px;">月</span>          日     时     分</span>
          </div>
        </div>
        <div style="padding: 5px 20px;">
          <p style="font-weight: bold;font-size: 16px;margin: 8px 0;">交接签收记录(以下由客户和配送人员共同确认) </p>
          <div style="display: flex;align-items: top;font-size: 14px;">
            <span style="width: 100%;display: block;margin: 0px 0 0px 0;line-height: 2;white-space: pre-wrap">客户签收时间:       <span style="margin-right:50px;">年</span> <span style="margin-right:30px;">月</span>     日     时     分</span>
          </div>
          <div style="display: flex;align-items: top;font-size: 14px;">
            <span
              style="width: 48%;display: inline-block;margin: 0px 0 0px 0;line-height: 2;white-space: pre-wrap">处方医院:</span>
          </div>
        </div>
      </div>

      <div
        style="border: 2px solid #333;margin: 30px auto 30px auto;width: 340px;text-align: center;font-size: 16px;line-height: 1.5;padding: 5px 25px;">
        国药控股湖南维安大药房连锁有限公司<br>产品保存知情同意书</div>

      <div style="line-height: 2;font-size: 14px;">
        尊敬的客户:
        <p style="text-indent: 2em;margin: 0;">您好!<span
            style="border-bottom: 1px solid #333;">请确认收到的药品，并查看包装是否完好，有无拆封痕迹，发票内容是否正确。</span>请您将药品置于药品包装上要求贮存的环境中。此外，由于此类药品价格昂贵，请患者慎重考虑购买的数量从而避免可能造成的不必要损失。
        </p>
        <p style="text-indent: 2em;margin: 0;">已确认药品完好无损。根据《药品经营质量管理规范》第一百七十三条规定:除药品质量原因外，药品经售出，概不退换。敬请谅解。</p>
        <p style="text-indent: 5em;margin: 0;">谢谢!祝早日康复!</p>
        <p style="text-indent: 2em;margin: 0;">以上信息我已确认并同意</p>
      </div>
      <div style="display: flex;align-items: top;">
        <span
          style="width: 48%;display: inline-block;margin: 0px 0 0px 0;line-height: 2;white-space: pre-wrap">客户确认签名:</span>
        <span style="width: 46%;display: inline-block;margin: 0px 0 0px 4%;line-height: 2;">配送人员签名: </span>
      </div>
    </div>
    */})

var codeReceiptTmp = heredoc(function (){/*
 <div
 style="margin: 0px auto 10px auto;width: 340px;text-align: center;font-size: 22px;line-height: 1.5;">
 冷链药品签收单</div>
  <p style="position:absolute;top:0px;left:2px;font-size: 14px;">国药控股湖南有限公司</p>
  <p style="position:absolute;top:13px;left:2px;font-size: 14px;">Sinopharm Group Hunan co.,Ltd</p>
 <p style="float:right;display: block;margin: 0px 20px 20px 0;line-height: 2;">订单组号:{OrderId}</p>
 <div id="receipt">
 <div class="Drugbox" style="border: 2px solid #333;">
   <div style="border-bottom: 1px solid #333;padding: 5px 20px;">
     <p style="font-weight: bold;font-size: 16px;margin: 8px 0;">配送信息</p>
     <div style="display: flex;align-items: top;font-size: 14px;">
       <span style="width: 54%;display: inline-block;margin: 0px 0 0px 0;line-height: 2;">产名、规格:
         {ProductName}{Specifications}</span>
       <span
         style="width: 21%;display: inline-block;margin: 0px 0 0px 2%;line-height: 2;">批号:{BatchNumber}</span>
       <span
         style="width: 21%;display: inline-block;margin: 0px 0 0px 2%;line-height: 2;">{Exp}</span>
     </div>

     <div style="display: flex;align-items: top;font-size: 14px;">
       <span style="width: 42%;display: inline-block;margin: 0px 0 0px 0;line-height: 2;">单价: {UnitPrice}</span>
       <span style="width: 16%;display: inline-block;margin: 0px 0 0px 2%;line-height: 2;">数量: {Number}</span>
       <span style="width: 26%;display: inline-block;margin: 0px 0 0px 2%;line-height: 2;">金额:
         {AmountMoney}</span>
     </div>

     <div style="display: flex;align-items: top;font-size: 14px;">
       <span style="width: 42%;display: inline-block;margin: 0px 0 0px 0;line-height: 2;">约定送货时间:
         {DeliveryTime}</span>
       <span style="width: 52%;display: inline-block;margin: 0px 0 0px 2%;line-height: 2;">约定送货地点:
         {Address}</span>
     </div>

     <div style="display: flex;align-items: top;font-size: 14px;">
       <span style="width: 42%;display: inline-block;margin: 0px 0 0px 0;line-height: 2;">收货人姓名:
         {ReceivingName}{Insurance}</span>
       <span style="width: 52%;display: inline-block;margin: 0px 0 0px 2%;line-height: 2;">收货人联系方式:
         {Contact}</span>
     </div>
         <div style="display: flex;align-items: top;font-size: 14px;">
       <span style="width: 42%;display: inline-block;margin: 0px 0 0px 0;line-height: 2;">诊断:
          </span>
       <span style="width: 52%;display: inline-block;margin: 0px 0 0px 2%;line-height: 2;">主治医师:
          </span>
     </div>
   </div>
   <div style="border-bottom: 1px solid #333;padding: 5px 20px;">
     <p style="font-weight: bold;font-size: 16px;margin: 8px 0;">配送开始记录(由配送人员填写)</p>
     <div style="display: flex;align-items: top;font-size: 14px;">
       <span style="width: 42%;display: inline-block;margin: 0px 0 0px 0;line-height: 2;white-space: pre-wrap">药品放入时间:  <span style="margin-right:50px;">年</span> <span style="margin-right:30px;">月</span>    日     时     分</span>
       <span style="width: 52%;display: inline-block;margin: 0px 0 0px 2%;line-height: 2;">包材编号: </span>
     </div>

     <div style="display: flex;align-items: top;font-size: 14px;margin-left:40px">
       <span
         style="width: 42%;display: inline-block;margin: 0px 0 0px 0;line-height: 2;white-space: pre-wrap">药品放入时温度:          ℃ </span>
       <span style="width: 52%;display: inline-block;margin: 0px 0 0px 2%;line-height: 2;">温度记录仪器编号: </span>
     </div>

     <div style="display: flex;align-items: top;font-size: 14px;">
       <span
         style="width: 42%;display: inline-block;margin: 0px 0 0px 0;line-height: 2;white-space: pre-wrap">药品开始配送时间:</span>
     </div>
   </div>
   <div style="padding: 5px 20px;">
     <p style="font-weight: bold;font-size: 16px;margin: 8px 0;">交接签收记录(以下由客户和配送人员共同确认) </p>
     <div style="display: flex;align-items: top;font-size: 14px;">
       <span style="font-size: 14px;width: 100%;display: block;margin: 0px 0 0px 0;line-height: 2;white-space: pre-wrap">客户签收时间:     <span style="margin-right:50px;">年</span> <span style="margin-right:30px;">月</span>       日     时     分</span>
     </div>
     <div style="display: flex;align-items: top;">
       <span
         style="font-size: 14px;width: 42%;display: inline-block;margin:0;line-height: 2;white-space: pre-wrap">配送到达温度:                   ℃</span>
     </div>
   </div>
 </div>

 <div
   style="margin: 0px auto 10px auto;width: 430px;text-align: center;font-size: 16px;line-height: 1;padding: 5px 25px;">
   国药控股湖南维安大药房连锁有限公司冷链<br>产品保存知情同意书</div>

 <div style="line-height: 1.8;font-size: 14px;">
   尊敬的客户:
   <p style="text-indent: 2em;margin: 0;">冷链产品通常是使用生物技术生产的，且来源于蛋白质，高温及冻结是影响蛋白质稳定性的主要因素，<span
       style="border-bottom: 1px solid #333;">冷链产品保存温度应为摄氏2度至8度</span>，温度过高或过低都会导致药品蛋白质结构受到损害，蛋白质将不再起作用并且减少药效，任何药效的损失都是永久的且不可挽回的
   </p>
   <p style="text-indent: 2em;margin: 0;">您购买的<span
       style="border-bottom: 1px solid #333;width: 120px;display: inline-block;min-height: 21px;"></span>，作为一项冷链产品，需要您在购买药品后于摄氏2度至8度保存。若您未按要求保存药品，导致的后果自负。<span
       style="border-bottom: 1px solid #333;">请确认您收到的药品外包装完好 口 &nbsp;&nbsp;无拆封痕迹 口 &nbsp;&nbsp;发票内容无误并签收 口</span>
   </p>
   <p style="text-indent: 2em;margin: 0;">请您在购买冷链产
     品时自备冷藏箱(包)及可使用的冰块，确保药品的保存温度全程符合冷藏链产品要求(摄氏2度至8度)。请务必在冷藏箱(包)的保温时限内将药品转移至摄氏2度至8度的冷藏冰箱内。</p>
   <p style="text-indent: 2em;margin: 0;">作为药品购买(使用)者，我已认真阅读上述内容，并已知晓未在摄氏2度至8度保存该药品可能发生的后果，我自愿购买并严格按照要求保存和使用。</p>
   <p style="text-indent: 2em;margin: 0;">已确认药品完好无损。根据《药品经营质量管理规范》第一百七十三条规定:除药品质量原因外，药品经售出，概不退换。敬请谅解。</p>
   <p style="text-indent: 5em;margin: 0;">谢谢!祝早日康复!</p>
   <p style="text-indent: 2em;margin: 0;">以上信息我已确认并同意</p>
 </div>
 <div style="display: flex;align-items: top;">
   <span
     style="width: 42%;display: inline-block;margin: 0px 0 0px 0;line-height: 2;white-space: pre-wrap">客户确认签名:</span>
   <span style="width: 52%;display: inline-block;margin: 0px 0 0px 2%;line-height: 2;">配送人员签名: </span>
 </div>
 </div>
    */})
window.Printer = function(){

}
window.Printer.prototype = {
    printOrder:function(orders,config){
        var doc = this.getTemp(orders)
        this.setPrinter(doc,config)
    },
    printTags:function(data,config){
        var doc = this.getTagsTemp(data)
        this.setPrinter(doc,config)
    },
    printMiniTags:function(data,config){
        var doc = this.getMiniTagsTemp(data)
        this.setPrinter(doc,config)
    },
    printReceipt:function (data,config){
        var doc = this.getReceiptTmp(data,receiptTemp)
        this.setPrinter(doc,config)
    },

    printColdReceipt:function (data,config){
        var doc = this.getReceiptTmp(data,codeReceiptTmp)
        this.setPrinter(doc,config)
    },
    getReceiptTmp:function (data,template){
        var temp = template
        Object.keys(data).map(function (v){
            var key = "{"+v+"}"
            temp = temp.replace(key,data[v])
        })
        return temp;
    },
    getColdReceiptTmp:function (data){
        var temp = codeReceiptTmp
        Object.keys(data).map(function (v){
            var key = "{"+v+"}"
            temp = temp.replace(key,data[v])
            console.log(temp)
        })
        return temp;
    },
    getNormalReceiptTmp:function (data){
        var temp = receiptTemp
        Object.keys(data).map(function (v){
            var key = "{"+v+"}"
            temp = temp.replace(key,data[v])
        })
        return temp;
    },
    getMiniTagsTemp:function (data) {
        var temp = miniTagsTemp;
        for (var i =0;i<data.length;i++){
            temp=  temp.replace("{img"+i+"}",data[i].url).replace("{code"+i+"}",data[i].code)
        }
        return temp
    },
    getTemp:function(data){
        var temp = printerTemp
        Object.keys(data).map(function (v){
            var key = "{"+v+"}"
            temp = temp.replace(key,data[v])
        })
        return temp;
    },
    setPrinter:function(temp,config){
        var pageNum = config.pageNum || 1; //打印页数
        var isviews = config.isviews || false //是否预览
        var w = config.w || 50
        var h = config.h || 40
        var printerIndex = config.printerIndex || 0
        var dirction = config.dirction || 1
        var fontsize = config.fontsize || 13
        LODOP=getLodop();
        LODOP.PRINT_INIT("");
        LODOP.SET_PRINT_STYLE("FontSize", fontsize);
        // if (config.title){
        //     if (config.title == "药品签收单"){
        //         LODOP.ADD_PRINT_TEXT(20, 340, 200, 300, "药品签收单");
        //     }else{
        //         LODOP.ADD_PRINT_TEXT(21, 300, 200, 200, config.title);
        //     }
        // }
        if(config.isReceipt){
            LODOP.ADD_PRINT_HTM(20, 30, 740, 1200, temp);
            LODOP.SET_PRINT_STYLE("Bold", 1);
        }else{
            LODOP.ADD_PRINT_HTM(0,0,"100%","100%",temp);
        }

        LODOP.SET_PRINTER_INDEXA(printerIndex);
        LODOP.SET_PRINT_PAGESIZE(dirction,w,h,"")
        LODOP.SET_PRINT_STYLE("FontName","微软雅黑");
        LODOP.SET_PRINT_COPIES(pageNum);
        if(isviews){
            LODOP.PREVIEW();
        }else{
            LODOP.PRINT();
        }

    },
    getTagsTemp:function (data) {
        return tagsTemp.replace("{imgUrl}",data.url).replace("{code}",data.code)
    }
}